package com.csi.sai.bl.dataview;

import java.util.ArrayList;

import javax.sql.DataSource;

import com.csi.sai.data.entities.Demand;
import com.csi.sai.data.entities.Vacancy;
import com.csi.sai.utilities.Utilities;
import com.csi.sai.utilities.templates.reports.VacancyTemplate;

public class GetDataViewVacancy extends GetDataView {

	private String htmlHeader;
	private String htmlBody;
	
	public GetDataViewVacancy(DataSource ds) {
		super(ds);
	}

	@Override
	protected void writeHeaders() {
		htmlHeader = VacancyTemplate.headers;
	}

	@Override
	protected <T> void writeBody(Generics<T> object) {
		StringBuffer sb = new StringBuffer();
		ArrayList<Vacancy> rsVacancy = (ArrayList<Vacancy>)object.getObject();
		for(Vacancy vacancy : rsVacancy) {
			String htmlRow = VacancyTemplate.row;
			
			String actualRow = htmlRow.
					replace("{idDemand}", ""+vacancy.getIdDemand()).
					replace("{vacancy}", ""+vacancy.getIdVacancy()).
					replace("{status}", vacancy.getEstatus()).
					replace("{dCreation}", Utilities.getDateByFormat(vacancy.getCreation(), Utilities.formatView)).
					replace("{founded}", ""+vacancy.getFounded()).
					replace("{stakeholder}", ""+vacancy.getStakeholder()).
					replace("{postulate}", ""+vacancy.getPostulates()).
					replace("{dFinish}", ""+Utilities.getDateByFormat(vacancy.getFinishDate(), Utilities.formatView)).
					replace("{comment}", ""+vacancy.getComment()).
					replace("{folio}", ""+vacancy.getFolio());
			
			sb.append(actualRow);
		}
		
		htmlBody = VacancyTemplate.body.replace("{body}", sb.toString());
	}

	@Override
	public String getHTMLCode() {
		return htmlHeader.replace("{body}", htmlBody);
	}

}
